﻿<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <title>病历管理</title>
    <?php PrintPageHead(); ?>
</head>
<body>
<style>
    table tr td{
        border: 1px #706e73 solid;
        text-align: left;
        padding: 4px;
    }
</style>

<?php

/**
 * Created by PhpStorm. User: ADun, Date: 14-10-15 下午10:11
 * Description:
 */
$openId=getCurrentUserOID();

if(empty($openId)) exit('参数错误');

$bm = new CUI数据中心(Page::m卖家中心_账目,$openId);


$修改病历 = $bm->生成有效链接('Seller16EditRecords',$_GET['state']);
$病历 = $bm->fc查病历($_GET['id']);

$评论列表 = $bm->get病历评论列表($_GET['id'],$_GET['page'],$_GET,$_POST['keywords']);
$当前用户已关注 = $bm->get当前用户是否关注该病例($_GET['id']);

if(!$当前用户已关注) $当前用户已关注 =array('id'=>0,'状态'=>'取消关注');
if($当前用户已关注['状态']==='关注') $状态 = '取消关注';
else $状态 = '关注';
?>
<!-- 配置文件 -->
<script type="text/javascript" src="../ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="../ueditor/ueditor.all.min.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container', {
        toolbars: [
            ['emotion', 'fontfamily', 'fontsize', '|',
                'simpleupload']
        ],
        autoHeightEnabled: true,
        autoFloatEnabled: true
    });
</script>
<div class="container-fluid">

    <div class="panel panel-primary">
        <div class="panel-heading text-center"><h3 class="panel-title">查看病历</h3></div>
        <div class="panel-body" style="width: 100%;">
            <div style="text-align: center; width: 90%; height: auto;margin-left: 4%">
                <h3 style=""><?= $病历['title']?></h3>
                <?php
                if($_SESSION['vo用户数据']['id'] ==$病历['主治医师id']){
                   if(!$病历['出院时间']) echo "<span><a href='".$修改病历."&id=".$病历['id']."'>修改病历</a> </span>". "<input type='button' onclick='f出院()' value='出院'>";
                }else  {
                    if($当前用户已关注) {?>

                        <input type="button" onclick="f关注('<?=$状态?>',<?=$当前用户已关注['id']?>)"     value="<?=$状态?>">
                        <?php

                    }
                }?>
                <input type="button" onclick="f分享()"    value="分享">
                <table style=" width: 100%;">
                    <tr><td style="width: 50%"><b>住院号:</b><?= $病历['title']?></td><td  rowspan="4" style="width: 40%">
                            <?php if($病历['照片']!=='没有图片') echo "<img style='width:90%' src='../".$病历['照片']."' >";?></td></tr>
                    <tr><td style="width: 45%"><b>床位号:</b><?= $病历['床位']?></td></tr>
                    <tr><td style="width: 45%"><b>医生:</b><?= $病历['主治医师']?></td></tr>
                    <tr><td style="width: 45%"><b>时间:</b><?= $病历['住院时间']."~".$病历['出院时间']?></td></tr>
                    <tr><td colspan="2"><b>详情:</b><?= $病历['详情']?></td></tr>

                </table>
            </div>


        </div>

        <div class="pinglun" style="width: 100%; text-align: center; ">

            <div  style="text-align:left; width: 90%; height: auto; margin-left: 4%">
                <span style="color: red"><b>评论专区</b></span>
                <?php foreach($评论列表['result'] as $key =>$value){?>
                    <div style="width: 100%; background-color:#f5f5dc; margin-top: 5px; padding: 2px;">
                        <span><b style="color: #0000cc"><?=$value['name']?></b>:<?=$value['评论']?></span>
                    </div>

                    <?php
                }?>
            </div>
            <div><?=$评论列表['show']?></div>
            <div  style="text-align:left; width: 90%; height: auto; margin-left: 4%">

                <?php
                if($_SESSION['vo用户数据']['所属店铺id'] ==$病历['店铺id']){?>
                    <form action="" method="post" style="text-align: center; width: 100%" >
                        <div class="form_d" >
                            <textarea id="container" name="content"></textarea>
                            <input type="submit" class="btn btn-lg btn-success " style="margin: 2px -80% 3px 0;  " value="评论" name="add" >
                        </div>
                    </form>
                <?php } ?>
            </div>
        </div>
    </div>




    <form>
        <input type="hidden" name="openId" value="<?=$openId?>" />
    </form>
</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="../resource/js/jquery-1.11.1.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="../resource/js/bootstrap.min.js"></script>
<script src="../resource/js/hermes.js"></script>

<script>
    function f关注(状态,id){
        $.post('agent_manages.php',{'关注id':id,"状态":状态,'病历id':<?=$_GET['id']?>,'参数':'修改关注病历'},function(data) {
            if(data){
                if(状态=='取消关注') alert("取消关注成功!");
                else alert("关注病历成功!");
                location.replace(location.href='');

            }else {
                alert("关注病历失败!");
            }
        })
    }

    function f出院(){
        $.post('agent_manages.php',{'病历id':'<?= $_GET['id']?>',"参数":'出院操作'},function(data){

            if(data){
                alert("出院操作成功!");
                location.replace(location.href);
            }else {
                alert("出院操作失败!");
            }
        });
    }

    function f分享(){
        $.post('agent_manages.php?state=<?=$_GET['state']?>',{'病历id':'<?= $_GET['id']?>',"参数":'分享病历'},function(data){

            if(data){
                alert("分享成功!");
            }else {
                alert("分享失败!");
            }
        });

    }

</script>
</body>
</html>
<?php
if(isset($_POST['add'])){
    if($_POST['content'] ===''){
        echo "<script>alert('请输入内容');</script>";
    }else{
        $do = new Do评论();
        $do->set_用户id($_SESSION['vo用户数据']['id']);
        $do->set_评论($_POST['content']);
        $do->set_病历id($_GET['id']);
        $do->set_时间(Date('Y-m-d H:i:s'));
        $插入 = $do->insert();
        if($插入){
            echo "<script>alert('评论成功');location.replace(location.href);</script>";
        }else{
            echo "<script>alert('评论失败');";
        }


    }

}
?>